﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ThreadConsole
{
    public class AutoRestEventDemo
    {
        static EventWaitHandle _waitHandle = new AutoResetEvent(false);

        public static void Waiter()
        {
            Console.WriteLine("Waiting...");
            _waitHandle.WaitOne();
            Console.WriteLine("Notified");
        }

        public static void Notify()
        {
            _waitHandle.Set();
        }
    }

    public class CountdonwEventDemo
    {
        static CountdownEvent _countdown = new CountdownEvent(3);

        public static void SaySomething(object thing)
        {
            Thread.Sleep(1000);
            Console.WriteLine(thing);
            _countdown.Signal();
        }

        public static void Wait()
        {
            _countdown.Wait();
        }
    }
}
